package com.ruoyi.testing.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.testing.domain.EmploymentNotice;
import com.ruoyi.testing.service.IEmploymentNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 从业告知书Controller
 * 
 * @author ruoyi
 * @date 2024-04-17
 */
@RestController
@RequestMapping("/testing/notice")
public class EmploymentNoticeController extends BaseController
{
    @Autowired
    private IEmploymentNoticeService employmentNoticeService;

    /**
     * 查询从业告知书列表
     */
    @GetMapping("/list")
    public TableDataInfo list(EmploymentNotice employmentNotice)
    {
        startPage();
        List<EmploymentNotice> list = employmentNoticeService.selectEmploymentNoticeList(employmentNotice);
        return getDataTable(list);
    }

    /**
     * 导出从业告知书列表
     */
    @Log(title = "从业告知书", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmploymentNotice employmentNotice)
    {
        List<EmploymentNotice> list = employmentNoticeService.selectEmploymentNoticeList(employmentNotice);
        ExcelUtil<EmploymentNotice> util = new ExcelUtil<EmploymentNotice>(EmploymentNotice.class);
        util.exportExcel(response, list, "从业告知书数据");
    }

    /**
     * 获取从业告知书详细信息
     */
    @GetMapping(value = "/{gzsId}")
    public AjaxResult getInfo(@PathVariable("gzsId") Long gzsId)
    {
        return success(employmentNoticeService.selectEmploymentNoticeByGzsId(gzsId));
    }

    /**
     * 获取委托协议中的从业告知书详细信息
     */
    @GetMapping(value = "/getEntrustment/{gzsId}")
    public AjaxResult getEntrustment(@PathVariable("gzsId") Long gzsId)
    {
        return success(employmentNoticeService.selectEntrustmentByGzsId(gzsId));
    }

    /**
     * 查询从业告知书列表
     */
    @GetMapping("/selectNotice/clientAndTestTime")
    public AjaxResult selectClientAndTestTimeNotice()
    {
        return AjaxResult.success(employmentNoticeService.selectClientAndTestTimeNotice());
    }

    /**
     * 新增从业告知书
     */
    @Log(title = "从业告知书", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmploymentNotice employmentNotice)
    {
        return AjaxResult.success(employmentNoticeService.insertEmploymentNotice(employmentNotice));
    }

    /**
     * 修改从业告知书
     */
    @Log(title = "从业告知书", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmploymentNotice employmentNotice)
    {
        return AjaxResult.success(employmentNoticeService.updateEmploymentNotice(employmentNotice));
    }

    /**
     * 删除从业告知书
     */
    @Log(title = "从业告知书", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gzsIds}")
    public AjaxResult remove(@PathVariable Long[] gzsIds)
    {
        return toAjax(employmentNoticeService.deleteEmploymentNoticeByGzsIds(gzsIds));
    }
}
